package com.moli.iov.admin.web.controller;

import com.moli.iov.admin.model.vo.req.VehicleUnauthReqVo;
import com.moli.iov.admin.service.IVehicleUnauthFacadeService;
import com.moli.iov.base.model.dto.res.VehicleUnauthResDto;
import com.moli.iov.model.dto.req.PageExtend;
import com.moli.iov.rest.RestResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 未授权记录管理
 * </p>
 *
 * @author zql
 * @since 2020/2/20 16:37
 */
@Slf4j
@RestController
@RequestMapping("/unauth")
public class VehicleUnauthController extends BaseController {

  @Autowired
  private IVehicleUnauthFacadeService vehicleUnauthFacadeService;

  /**
   * 分页查询 未授权登录
   * @param vehicleUnauthReqVo
   * @return
   */
  @RequestMapping("/listPageVehicleUnauth")
  public RestResponse<PageExtend<VehicleUnauthResDto>> listPageVehicleUnauth(
      @RequestBody(required = false) VehicleUnauthReqVo vehicleUnauthReqVo){
    if(vehicleUnauthReqVo == null){
      vehicleUnauthReqVo = new VehicleUnauthReqVo();
    }
    assembleUserInfo(vehicleUnauthReqVo);
    return vehicleUnauthFacadeService.listPageVehicleUnauth(vehicleUnauthReqVo);
  }

  /**
   * 处理
   * @param vehicleUnauthReqVo
   * @return
   */
  @RequestMapping("/updateVehicleUnauthOfProcess")
  public RestResponse updateVehicleUnauthOfProcess(
      @RequestBody @Validated({VehicleUnauthReqVo.Process.class}) VehicleUnauthReqVo vehicleUnauthReqVo){
    assembleUserInfo(vehicleUnauthReqVo);
    return vehicleUnauthFacadeService.updateVehicleUnauthOfProcess(vehicleUnauthReqVo);
  }

  /**
   * 导出
   */
  @RequestMapping("/export")
  public void export(@RequestBody(required = false) VehicleUnauthReqVo vehicleUnauthReqVo,
      HttpServletRequest req, final HttpServletResponse res){
    try{
      if(vehicleUnauthReqVo == null){
        vehicleUnauthReqVo = new VehicleUnauthReqVo();
      }
      assembleUserInfo(vehicleUnauthReqVo);
      vehicleUnauthFacadeService.export(vehicleUnauthReqVo, req, res);
    }catch(Exception e){
      log.error("未授权记录 异常", e);
    }
  }
}
